﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>


<div class="fr-widget white-space">
    <div class="header">
        <div class="icon">
        </div>
        <span>
            <%=ForumContext.GetText("SEARCH", "SEARCH_ADVANCED")%>
        </span>
    </div>

    <%using(Html.BeginForm("AdvSearch","Forum",FormMethod.Post,new {@id = "Search", @onRequest = "$.MvcForum.showLoading();", @onSuccess = "$.MvcForum.hideLoading();$.MvcForum.ajaxSuccess(msg);"}))
       {%>

       <%=Html.AntiForgeryTokenX("SEARCH")%>
    <table cellpadding="0" cellspacing="1" width="100%">
        <tr>
            <td class="table-cell width50 valign-top">
                <fieldset>
                    <legend>
                        <%=ForumContext.GetText("SEARCH", "BY_KEYWORDS")%>
                    </legend>
                    <table cellpadding="0" cellspacing="5" width="100%">
                        <tr>
                            <td style="width:120px">
                                <select id="_searchwithin" name="_searchwithin" class="select">
                                    <option value="0">
                                        <%=ForumContext.GetText("SEARCH", "WITH_IN_ALL")%></option>
                                    <option value="1">
                                        <%=ForumContext.GetText("SEARCH", "WITH_IN_SUBJECT")%></option>
                                    <option value="2">
                                        <%=ForumContext.GetText("SEARCH", "WITH_IN_MESSAGE")%></option>
                                </select>
                            </td>
                            <td>
                                <input type="text" name="_keywords" maxlength="100" id="_keywords" onkeydown="searchTriger(event)" class="w90 input {validate:{required:true}}" />
                            </td>
                        </tr>
                    </table>
                </fieldset>
            </td>
            <td class="table-cell valign-top">
                <fieldset>
                    <legend>
                        <%=ForumContext.GetText("SEARCH", "BY_USERS")%>
                    </legend>
                    <table cellpadding="0" cellspacing="5" width="100%">
                        <tr>
                            <td class="width20">
                                <select id="_SearchKeywordType" name="_SearchKeywordType" style="width: 120px" class="select">
                                    <option value="0">
                                        <%=ForumContext.GetText("SEARCH", "INCLUDE")%></option>
                                    <option value="1">
                                        <%=ForumContext.GetText("SEARCH", "STARTWITH")%></option>
                                    <option value="2">
                                        <%=ForumContext.GetText("SEARCH", "ENDWITH")%></option>
                                    <option value="3">
                                        <%=ForumContext.GetText("SEARCH", "EXACT")%></option>
                                </select>
                            </td>
                            <td>
                                <input type="text" class="input" maxlength="80" name="_UserName" id="_UserName" onkeydown="searchTriger(event)" />
                            </td>
                        </tr>
                    </table>
                </fieldset>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="table-caption">
                <%=ForumContext.GetText("SEARCH", "OTHER_OPTIONS")%>
            </td>
        </tr>
        <tr>
            <td class="table-cell valign-top">
                <fieldset>
                    <legend>
                        <%=ForumContext.GetText("SEARCH", "POSTS_WITH")%></legend>
                    <table cellpadding="0" cellspacing="5" width="100%">
                        <tr>
                            <td class="width10">
                                <select id="_SearchPostsWith" name="_SearchPostsWith" class="select">
                                    <option value="0">
                                        <%=ForumContext.GetText("SEARCH", "ATLEAST")%></option>
                                    <option value="1">
                                        <%=ForumContext.GetText("SEARCH", "ATMOST")%></option>
                                </select>
                            </td>
                            <td>
                                <input type="text" id="_Replies" name="_Replies" class="input {validate:{digits:true}}" value="0" style="width: 30px" />
                                <%=ForumContext.GetText("TOPICS", "REPLY")%>
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <fieldset>
                    <legend>
                        <%=ForumContext.GetText("SEARCH", "FIND_POSTS_FROM")%></legend>
                    <select id="_FindPostsFrom" name="_FindPostsFrom" onchange="findPostsChange(this.value)"
                        class="select">
                        <option value="0">
                            <%=ForumContext.GetText("SEARCH", "ANYDATE")%></option>
                        <option value="1">
                            <%=ForumContext.GetText("SEARCH", "YESTERDAY")%></option>
                        <%
           string _dayAgo = ForumContext.GetText("SEARCH", "DAYSAGO");
           for (int i = 5; i < 90; i = i + 5)
           {

%>
                        <option value="<%=i%>">
                            <%=String.Format(_dayAgo, i)%></option>
                        <%
           }%>
                    </select>
                    <select id="_FindPostsTo" name="_FindPostsTo" style="width: 100px" disabled="disabled"
                        class="select">
                        <option value="0">
                            <%=ForumContext.GetText("SEARCH", "AND_NEWER")%></option>
                        <option value="1">
                            <%=ForumContext.GetText("SEARCH", "AND_OLDER")%></option>
                    </select>
                </fieldset>
                <fieldset>
                    <legend>
                        <%=ForumContext.GetText("SEARCH", "RESULTS_SORT_BY")%></legend>
                    <select id="_sortby" name="_sortby" class="select">
                        <option value="1">
                            <%=ForumContext.GetText("SEARCH", "LASTPOSTED")%></option>
                        <option value="2">
                            <%=ForumContext.GetText("SEARCH", "CREATED")%></option>
                        <option value="3">
                            <%=ForumContext.GetText("SEARCH", "SUBJECT")%></option>
                        <option value="4">
                            <%=ForumContext.GetText("SEARCH", "TOTALREPLIES")%></option>
                        <option value="5">
                            <%=ForumContext.GetText("SEARCH", "TOTALVIEWS")%></option>
                        <option value="6">
                            <%=ForumContext.GetText("SEARCH", "LASTEDITED")%></option>
                    </select>
                    <select id="_sortorder" name="_sortorder" style="width: 100px" class="select">
                        <option value="ASC">
                            <%=ForumContext.GetText("SEARCH", "ASC")%></option>
                        <option value="DESC">
                            <%=ForumContext.GetText("SEARCH", "DESC")%></option>
                    </select>
                </fieldset>
                <fieldset>
                    <legend>
                        <%=ForumContext.GetText("SEARCH", "SHOW_RESULTS_AS")%></legend>
                    <select id="_ShowResultsAs" name="_ShowResultsAs" class="select">
                        <option value="0">
                            <%=ForumContext.GetText("SEARCH", "TOPICS")%></option>
                       <%-- <option value="1">
                            <%=ForumContext.GetText("SEARCH", "POSTS")%></option>--%>
                    </select>
                </fieldset>
            </td>
            <td class="table-cell valign-top">
                <select style="width: 100%; height: 280px" multiple="multiple" id="_Forums" name="_Forums">
                    <option value="0" class="bold" selected="selected">
                        <%=ForumContext.GetText("SEARCH", "ALL_FORUMS")%></option>
                    <%
           var _forums = ForumsRepository.ForumJump();

           foreach (var forum in _forums)
           {

%>
                    <option value="<%=forum.ForumId%>" class="<%=forum.ParentId == 0 ? "bold" : ""%>">
                        <%=ForumContext.Padding(forum.Level) + forum.ForumName%></option>
                    <%
           }%>
                </select>
              <%--  <br />
                <input type="checkbox" id="_issearchinsubforums" name="_issearchinsubforums" checked="checked" /><label
                    for="_issearchinsubforums"><%=ForumContext.GetText("SEARCH", "SEARCH_IN_SUB_FORUMS")%></label>--%>
            </td>
        </tr>
        <tr>
            <td class="table-cell">
                &nbsp;
            </td>
            <td class="table-cell">
                <input type="button" value="Tìm kiếm" onclick="$.MvcForum.ajaxSubmit('Search')" />
            </td>
        </tr>
    </table>

    <%
       }%>
</div>
<script type="text/javascript">

//<![CDATA[

    function findPostsChange(_val) {

        if (_val == 0) {

            $('#_FindPostsTo').attr("disabled", true);
        }
        else {

            $('#_FindPostsTo').attr("disabled", false);
        }

    };



    function searchTriger(event) {

        if ($.MvcForum.isEnter(event)) {

        }

    };


    $(function () {
        findPostsChange($('#_FindPostsFrom option:selected').val());
    });


       //]]>
    
</script>
